package com.hans.myscanner.Scanner.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ListView;

import com.haha.extend.HeadBar.BaseHeaderView;
import com.haha.extend.HeadBar.ImageInLeftAndRight;
import com.hans.myscanner.R;
import com.hans.myscanner.adapter.ContactInfoAdapter;
import com.hans.myscanner.entity.ContactEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/7/9.
 */
public class EncodeContactActivity extends AppCompatActivity {
    //编码
    private ImageInLeftAndRight header;
    private CheckBox contactName,contactAddress;
    private ListView phoneNumLV,emailLV;
    private View genarateQRBtn;

    public static final String KEY_CONTACT_ENTITY = "contact_entity";
    private static final String KEY_PHONE_NUMBER = "phone";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_encode_contact);
        findView();
        initView();
    }
    private void findView(){
        header= (ImageInLeftAndRight) findViewById(R.id.header);
        contactName= (CheckBox) findViewById(R.id.contact_name);
        contactAddress= (CheckBox) findViewById(R.id.contact_address);
        phoneNumLV= (ListView) findViewById(R.id.phone_num_list);
        emailLV= (ListView) findViewById(R.id.email_list);
        genarateQRBtn=findViewById(R.id.generate_qr);
    }
    private void initView(){
        Intent intent=getIntent();
        if(intent!=null){
            ContactEntity contactEntity=intent.getParcelableExtra(KEY_CONTACT_ENTITY);
            if(!TextUtils.isEmpty(contactEntity.getName())){contactName.setText(contactEntity.getName());}
            List<String> phones=contactEntity.getPhoneNums();
            if(phones!=null && phones.size()>0){
                phoneNumLV.setAdapter(new ContactInfoAdapter(this,phones));
            }
            List<String> emails=contactEntity.getEmails();
            if(emails!=null&& emails.size()>0){
                emailLV.setAdapter(new ContactInfoAdapter(this,emails));
            }
            if(!TextUtils.isEmpty(contactEntity.getAddress())){contactAddress.setText(contactEntity.getAddress());}
        }
        header.setOnHeaderClickListener(onHeaderClickListener);
        genarateQRBtn.setOnClickListener(onClickListener);
    }


    private BaseHeaderView.OnHeaderClickListener onHeaderClickListener = new BaseHeaderView.OnHeaderClickListener() {
        @Override
        public void onHeaderLeftClicked() {
            finish();
        }

        @Override
        public void onHeaderCenterClicked() {

        }

        @Override
        public void onHeaderRightClicked() {

        }
    };
    private View.OnClickListener onClickListener=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(v.getId()== R.id.generate_qr){

            }
        }
    };
}
